package com.gz.moreaseManager.modules.service.impl;

import com.gz.moreaseManager.core.base.Constants;
import com.gz.moreaseManager.modules.entity.AuthInfo;
import com.gz.moreaseManager.modules.mapper.AuthInfoMapper;
import com.gz.moreaseManager.modules.service.IAuthInfoService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.gz.moreaseManager.utils.UtilTool;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 会员信息 服务实现类
 * </p>
 *
 * @author wike
 * @since 2019-02-26
 */
@Service
public class AuthInfoServiceImpl extends ServiceImpl<AuthInfoMapper, AuthInfo> implements IAuthInfoService {

    @Resource
    private  AuthInfoMapper authInfoMapper;

    /**
     * 根据权限码获取会员信息
     * @param authCode
     * @return
     */
    private List<AuthInfo> findAuthInfoListByAuthCode( String authCode ){
        if(UtilTool.isNotBlank( authCode  )){
            List<AuthInfo> list = authInfoMapper.findAuthByAuthCode( authCode );
            if( UtilTool.isNotBlank( list ))
                return list ;
        }
        return null;

    }

    /**
     * 获取会员章程信息
     * @return
     */
    public AuthInfo findAuthConstitution(){
        List<AuthInfo> list = findAuthInfoListByAuthCode(Constants.AUTH_TYPE_CONSTITUTION);
        if( UtilTool.isNotBlank( list ) && list.size() == 1)
            return list.get(0);
        return null;
    }

    /**
     * 获取会员章程信息
     * @return
     */
    public List<AuthInfo> findAuthActivity(){
        List<AuthInfo> list = findAuthInfoListByAuthCode(Constants.AUTH_TYPE_ACTIVITY);
        if( UtilTool.isNotBlank( list ) )
            return list;
        return null;
    }
}
